#ifndef __IAM_RASTERVIEW_H__
#define __IAM_RASTERVIEW_H__

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

/**
 * @brief Float32 栅格视角对象
 * 
 */
typedef struct _IAM_RasterView_F32_
{
    size_t m_size_x; // 栅格图宽
    size_t m_size_y; // 栅格图高
    float* m_pdata;  // 栅格数据指针, 不负责创建和释放
    float m_nodata;  // 无效数据, 默认为 NAN
} _IAM_RasterView_F32;
typedef _IAM_RasterView_F32* IAM_RasterView_F32;

/* 初始化 Float32 栅格视角对象 */
IAM_RasterView_F32 IAM_RasterView_init0_F32(void);
IAM_RasterView_F32 IAM_RasterView_init_F32(size_t size_x, size_t size_y, float* pdata);

/* 重新设置 Float32 栅格视角对象 */
void IAM_RasterView_reset_F32(IAM_RasterView_F32 view, size_t size_x, size_t size_y, float* pdata);

/* 释放 Float32 栅格视角对象 */
void IAM_RasterView_release_F32(IAM_RasterView_F32* p_view);

/* 获取栅格视角对象在坐标(xid, yid)处的值 */
float IAM_RasterView_getValue_F32(const IAM_RasterView_F32 view, size_t xid, size_t yid);

/* 设置栅格视角对象在坐标(xid, yid)处的值 */
void IAM_RasterView_setValue_F32(IAM_RasterView_F32 view, size_t xid, size_t yid, float value);

/* 判读value是否为无效数据 */
bool IAM_RasterView_isNodata_F32(const IAM_RasterView_F32 view, float value);

/**
 * @brief Float64 栅格视角对象
 * 
 */
typedef struct _IAM_RasterView_F64_
{
    size_t m_size_x; // 栅格图宽
    size_t m_size_y; // 栅格图高
    double* m_pdata;  // 栅格数据指针
    double m_nodata;  // 无效数据, 默认为 NAN
} _IAM_RasterView_F64;
typedef _IAM_RasterView_F64* IAM_RasterView_F64;

/* 初始化 Float64 栅格视角对象 */
IAM_RasterView_F64 IAM_RasterView_init0_F64(void);
IAM_RasterView_F64 IAM_RasterView_init_F64(size_t size_x, size_t size_y, double* pdata);

/* 重新设置 Float64 栅格视角对象 */
void IAM_RasterView_reset_F64(IAM_RasterView_F64 view, size_t size_x, size_t size_y, double* pdata);

/* 释放 Float64 栅格视角对象 */
void IAM_RasterView_release_F64(IAM_RasterView_F64* p_view);

/* 获取栅格视角对象在坐标(xid, yid)处的值 */
double IAM_RasterView_getValue_F64(const IAM_RasterView_F64 view, size_t xid, size_t yid);

/* 设置栅格视角对象在坐标(xid, yid)处的值 */
void IAM_RasterView_setValue_F64(IAM_RasterView_F64 view, size_t xid, size_t yid, double value);

/* 判读value是否为无效数据 */
bool IAM_RasterView_isNodata_F64(const IAM_RasterView_F64 view, double value);

/* 表示复数的浮点数数据 */
typedef struct _CpxFloat_
{
    float real, imag;
} CpxFloat;

typedef struct _CpxDouble_
{
    double real, imag;
} CpxDouble;


/**
 * @brief Complex Float32 栅格视角对象
 * 
 */
typedef struct _IAM_RasterView_CF32_
{
    size_t m_size_x; // 栅格图宽
    size_t m_size_y; // 栅格图高
    CpxFloat* m_pdata;  // 栅格数据指针, 不负责创建和释放
    CpxFloat m_nodata;  // 无效数据, 默认为 NAN
} _IAM_RasterView_CF32;
typedef _IAM_RasterView_CF32* IAM_RasterView_CF32;

/* 初始化 Complex Float32 栅格视角对象 */
IAM_RasterView_CF32 IAM_RasterView_init0_CF32(void);
IAM_RasterView_CF32 IAM_RasterView_init_CF32(size_t size_x, size_t size_y, CpxFloat* pdata);

/* 重新设置 Complex Float32 栅格视角对象 */
void IAM_RasterView_reset_CF32(IAM_RasterView_CF32 view, size_t size_x, size_t size_y, CpxFloat* pdata);

/* 释放 Complex Float32 栅格视角对象 */
void IAM_RasterView_release_CF32(IAM_RasterView_CF32* p_view);

/* 获取栅格视角对象在坐标(xid, yid)处的值 */
CpxFloat IAM_RasterView_getValue_CF32(const IAM_RasterView_CF32 view, size_t xid, size_t yid);

/* 设置栅格视角对象在坐标(xid, yid)处的值 */
void IAM_RasterView_setValue_CF32(IAM_RasterView_CF32 view, size_t xid, size_t yid, CpxFloat value);

/* 判读value是否为无效数据 */
bool IAM_RasterView_isNodata_CF32(const IAM_RasterView_CF32 view, CpxFloat value);

/**
 * @brief Complex Float64 栅格视角对象
 * 
 */
typedef struct _IAM_RasterView_CF64_
{
    size_t m_size_x; // 栅格图宽
    size_t m_size_y; // 栅格图高
    CpxDouble* m_pdata;  // 栅格数据指针, 不负责创建和释放
    CpxDouble m_nodata;  // 无效数据, 默认为 NAN
} _IAM_RasterView_CF64;
typedef _IAM_RasterView_CF64* IAM_RasterView_CF64;

/* 初始化 Complex Float64 栅格视角对象 */
IAM_RasterView_CF64 IAM_RasterView_init0_CF64(void);
IAM_RasterView_CF64 IAM_RasterView_init_CF64(size_t size_x, size_t size_y, CpxDouble* pdata);

/* 重新设置 Complex Float64 栅格视角对象 */
void IAM_RasterView_reset_CF64(IAM_RasterView_CF64 view, size_t size_x, size_t size_y, CpxDouble* pdata);

/* 释放 Complex Float64 栅格视角对象 */
void IAM_RasterView_release_CF64(IAM_RasterView_CF64* p_view);

/* 获取栅格视角对象在坐标(xid, yid)处的值 */
CpxDouble IAM_RasterView_getValue_CF64(const IAM_RasterView_CF64 view, size_t xid, size_t yid);

/* 设置栅格视角对象在坐标(xid, yid)处的值 */
void IAM_RasterView_setValue_CF64(IAM_RasterView_CF64 view, size_t xid, size_t yid, CpxDouble value);

/* 判读value是否为无效数据 */
bool IAM_RasterView_isNodata_CF64(const IAM_RasterView_CF64 view, CpxDouble value);

#endif

